package com.example.blog.mapper;

import com.example.blog.entity.Article;
import com.example.blog.entity.Comment;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CommentMapper {
    @Insert("INSERT INTO comment (article_id, user_id, comment_time, content,username) VALUES (#{article_id}, #{user_id}, NOW(), #{content},#{username})")
    int insertComment(int article_id,int user_id,String content,String username);

    // 可以添加其他查询评论的方法，例如：
    @Select("SELECT c.*, u.name FROM comment c JOIN user u ON c.user_id = u.id WHERE c.article_id = #{article_id}")
    List<Comment> selectCommentsByArticleId(int article_id);

    @Select("SELECT * FROM article WHERE id = #{id}")
    Article selectArticleById(int id);

}